<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>链式调用原理</title>
</head>
<body>
  <script>
    // 创建一个bird类
    function Bird(name) {
      this.name = name;
      this.run = function () {
        document.write(name + '' + 'start run;')
        return this // return this 返回当前调用方法的对象
      }
      this.stopRun = function () {
        document.write(name + '' + 'start run;')
        return this
      }
      this.sing = function () {
        document.write(name + '' + 'start sing;')
        return this
      }
      this.stopSing = function () {
        document.write(name + '' + 'start stopSing;')
        return this
      }
    }
    var bird = new Bird('测试')
    bird.run().sing().stopSing().stopRun()

    // 创建一个 构造函数
    function count(num) {
      this.num = num
      this.add = function() {
        this.num = num + 111
        return this
      }
      this.sub = function() {
        this.num = this.num - 2
        return this
      }
      this.sayLove = function () {
        document.write(this.num + 300)
        this.num = this.num + 300
        return this
      }
    }
    let obj = new count(111)
    obj.add().sub().sayLove()
  </script>
</body>
</html>